﻿using System;
using System.Windows.Forms;

namespace function.guanji
{
    public partial class UserControlguanji : UserControl
    {
        private int hour1;
        private int minite1;
        private Timer timer_guanji;

        public UserControlguanji()
        {
            InitializeComponent();
            this.timer_guanji = new Timer();
            this.timer_guanji.Tick += new EventHandler(this.timer2_Tick);

            this.Disposed += UserControlguanji_Disposed;
        }

        private void UserControlguanji_Disposed(object sender, EventArgs e)
        {
            this.timer_guanji.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.hour1 = int.Parse(this.textBox1.Text.Trim());
            }
            catch (Exception exception1)
            {
                MessageBox.Show("输入时间!!!");
                return;
            }
            try
            {
                this.minite1 = int.Parse(this.textBox2.Text.Trim());
            }
            catch (Exception exception2)
            {
                MessageBox.Show("输入时间!!!");
                return;
            }
            this.label4.Text = string.Concat(new object[] { this.hour1, "小时", this.minite1, "分" });
            this.timer_guanji.Interval = 60000;
            this.timer_guanji.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer_guanji.Enabled = false;
            this.label4.Text = "提示";
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (this.hour1 == 0)
            {
                if (this.minite1 == 0)
                {
                    shoutdown.DoExitWin(1);
                    return;
                }
                this.minite1--;
            }
            else if (this.minite1 == 0)
            {
                this.hour1--;
                this.minite1 = 59;
            }
            else
            {
                this.minite1--;
            }
            this.label4.Text = string.Concat(new object[] { this.hour1, "小时", this.minite1, "分" });
        }
    }
}